package com.itheima.mylistdemo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class MyListDemo2 {
    public static void main(String[] args) {
        List<String>list = new ArrayList<>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        list.add("ddd");
        //method1(list);
        //method2(list);
        //method3(list);
        //method4();
        String[] strs = list.toArray(new String[list.size()]);
        System.out.println((Arrays.toString(strs)));
    }

    private static void method4() {
        //此方法创建的集合是不可变的集合
        List<String> list1 = List.of("1","2");
        //获取数据并封装成list集合的售后比较常用
    }

    //      指定索引处替换为""
    private static void method3(List<String> list) {
        String result = list.set(3, "eee");
        System.out.println(result);
        System.out.println(list);
    }

    //      删除制定索引处的元素
    private static void method2(List<String> list) {
        String s = list.remove(0);
        System.out.println(s);
        System.out.println(list);
    }
//  指定索引处插入元素,后面的往后顺延
    private static void method1(List<String> list) {
        list.add(0,"qqq");
        System.out.println(list);
        //此时最大索引4,长度为5,6索引,长度为7,所以索引越界
     //   list.add(6,"qqq");

    }
}
